/*
* 泛型类
* <T> : 表示当前类是一个泛型类
* */
class MyArray<T>{
    public Object [] array = new Object[3];

    public void setArray(int pos,T val){
        array[pos] = val;
    }

    public T getVal(int pos){
        return (T)array[pos];
    }
}

public class Test {

    public static void main(String[] args) {
        MyArray<Integer> myArray1 = new MyArray<Integer>();
        myArray1.setArray(1,10);//在编译的时候，自动进行类型的检查
//        myArray1.setArray(2,"hello");
        System.out.println(myArray1.getVal(1));//在编译的时候，自动进行类型的转换

        MyArray<String> myArray2 = new MyArray<String>();
        myArray2.setArray(1,"hello");
//        myArray2.getVal(2,7)
        System.out.println(myArray2.getVal(1));

    }

    public static void main4(String[] args) {
        MyArray myArray = new MyArray();
        myArray.setArray(1,10);
        myArray.setArray(2,"hello");

        String ret = (String)myArray.getVal(2);
    }

    public static void main3(String[] args) {
        Integer a = 100;
        Integer b = 100;
        System.out.println(a == b);

        Integer aa = 200;
        Integer bb = 200;
        System.out.println(aa == bb);
    }

    public static void main2(String[] args) {
        //拆箱：
        Integer a = 100;
        int i = a;//自动拆箱

        int ii = a.intValue();//显式拆箱
        double b = a.doubleValue();

        System.out.println(a);
        System.out.println(i);
    }

    public static void main1(String[] args) {
        //装箱：
        int i = 10;
        Integer a = i;//自动装箱

        Integer b = Integer.valueOf(17);//显式装箱
    }
}
